package presentacion;

import java.awt.BorderLayout;
import java.awt.Component;
import java.util.List;
import javax.swing.DefaultListModel;
import logica.ItemLista;

/**
 * Este diálogo muestra los postulantes que han empatado el puntaje para un concurso
 * @author FedEx
 */
public class DialogoEmpates extends javax.swing.JPanel {

    private DefaultListModel modelo;
    private String retorno;
    
    /** Creates new form DialogoEmpates */
    public DialogoEmpates(List<ItemLista> postulantes) {
        initComponents();
        retorno= "";
        modelo= new DefaultListModel();
        lista.setModel(modelo);
        dialogo.getContentPane().setLayout(new BorderLayout());
        for (ItemLista i : postulantes)
            modelo.addElement(i.getNombrePostulante());
        puntaje.setText(String.valueOf(postulantes.get(0).getPuntaje()));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dialogo = new javax.swing.JDialog();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lista = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        puntaje = new javax.swing.JLabel();
        seleccionar = new javax.swing.JButton();

        dialogo.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        dialogo.setTitle("Empates");
        dialogo.setModal(true);
        dialogo.setResizable(false);

        javax.swing.GroupLayout dialogoLayout = new javax.swing.GroupLayout(dialogo.getContentPane());
        dialogo.getContentPane().setLayout(dialogoLayout);
        dialogoLayout.setHorizontalGroup(
            dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        dialogoLayout.setVerticalGroup(
            dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        jLabel1.setText("Postulantes empatados: seleccione el ganador");

        lista.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(lista);

        jLabel2.setText("Puntaje:");

        puntaje.setText("jLabel3");

        seleccionar.setText("Seleccionar");
        seleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seleccionar(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(puntaje, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE))
                    .addComponent(seleccionar, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(puntaje))
                .addGap(18, 18, 18)
                .addComponent(seleccionar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void seleccionar(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seleccionar
    retorno= (String) lista.getSelectedValue();
    if (retorno != null)
        dialogo.setVisible(false);
}//GEN-LAST:event_seleccionar

 /**
 * Retorna el nombre del postulante seleccionado.
 * 
 * @param c componente padre sobre el cual se centrará este diálogo
 * @return String con el nombre de postulante seleccionado, que será becario
 */
    public String hacerVisible(Component c)
    {
        dialogo.getContentPane().add(this, BorderLayout.CENTER);
        dialogo.pack();
        dialogo.setLocationRelativeTo(c);
        dialogo.setVisible(true);
        dialogo.dispose();
        return retorno;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog dialogo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList lista;
    private javax.swing.JLabel puntaje;
    private javax.swing.JButton seleccionar;
    // End of variables declaration//GEN-END:variables
}
